<template>
	<view class="bg-gray height100vh">
		<view class="lineGray"></view>
		<view class="padding">
			<view v-for="(item,index) in list" class="padding bgWhitecircleRect marginBottom" @click="clickItem(item)">
				<view class="line">
					<view>
						<image v-show="type==1" class="icon-normal" src="/static/bluenotice.png"></image>
						<image v-show="type==2" class="icon-normal" src="/static/color-pic.png"></image>
						<image v-show="type==4" class="icon-normal" src="/static/redbonue.png"></image>
					</view>
					<view class="bigEmpty marginLeft">
						{{item.name}}
					</view>
					<view>
						{{item.createTime}}
					</view>
					
				</view>
				<view class="marginTop">
					{{item.content}}
				</view>
				<view class="line">
					<image class="marginTop " v-if="item.job.finalResultImages.length>0" :src="item.job.finalResultImages[0]"></image>
				</view>
				
				<view class="line marginTop">
					<view class="bigEmpty"></view>
					<view v-show="type==2" class="textblue14 ">查看详情</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import request from "/common/request.js"
	export default {
		data() {
			return {
				list: [],
			    jobIdList:[],
				loading: false,
				page: 0,
				type: "1"
			}
		},
		onShareAppMessage(res) {
			return {
				title: '设辑-产品设计智能生成AI',
				path: '/pages/HomePage/HomePage',
				imageUrl: '/static/black-logo.png'
			}
		},
		// 自定义页面的分享到朋友圈
		onShareTimeline(res) {
			return {
				title: '设辑-产品设计智能生成AI',
				path: '/pages/HomePage/HomePage',
				imageUrl: '/static/black-logo.png'
			}
		},
		onLoad: function(query) {
			this.type = query.type
			switch (this.type) {
				case "3":
					uni.setNavigationBarTitle({
						title: "系统公告"
					})
					this.requstData();
					break
				case "4":
					uni.setNavigationBarTitle({
						title: "收益"
					})
					this.requstData();
					break
				case "2":
					uni.setNavigationBarTitle({
						title: "AI生成"
					})
					this.requstData();
					break
				case "1":
					uni.setNavigationBarTitle({
						title: "服务反馈"
					})
					this.requstData();
					break
			}

		},
		
		onReachBottom() {
			this.requstData();
		},
		onShow: function() {


		},
		onReady: function() {

		},
		methods: {
			clickItem(item) {
				var job = item.job;
				const that = this
				var size = "1:1";
				var sizeArray = [
					"1:1",
					"1:1",
					"1:2",
					"4:3",
					"3:4",
					"16:9",
					"9:16"
				]
				size = sizeArray[job.width2height]
				var module = "精彩"
				var moduleArray = [
					"1:1",
					"1:1",
					"1:2",
					"1:2",
					"精彩",
					"细腻",
					"动漫",
					"创意",
					"照片"
				]
				module = moduleArray[job.module]
				var style = "长焦镜头"
				var styleArray = [
					"长焦镜头",
					"长焦镜头",
					"手绘背景",
					"CG数字渲染",
					"哑光颜",
					"X光片",
					"矢量设计海报",
					"极简线条画",
					"炭笔画",
					"更多"
				]
				style = styleArray[job.style]
				var url1 =
					"/pages/CreatePictureResult/CreatePictureResult?id=" +
					job.id + '&goodContent=' + job.cmd + '&moduleIndex=' +
					job.module +
					'&styleIndex=' +
					job.style + "&sizeTab1Index=" + job.width2height +
					"&createTime=" + job.createTime +
					"&size=" + size +
					"&style=" + style +
					"&badContent=" + "" +
					"&module=" + module
				uni.navigateTo({
					url: url1
				})
			},
			requstData() {
				const that = this;
				if (that.loading) {
					return
				}
				that.loading = true;

				var url = getApp().globalData.apiUrl + "/api/v1/notice/mine";
				if (this.type == "3") {
					url = getApp().globalData.apiUrl + "/api/v1/notice";
				}
				console.log("kkkk")
				request(url, "GET", {
						page: this.page,
						size: 20,
						type: this.type
					}, uni.getStorageSync("token"))
					.then(function(res) {
						console.log('返回正确回调', res)
						that.page = that.page + 1;
						that.loading = false;
						var list = res.data
						var tempList=[];
						for(var index=0;index<list.length;index++){
							var item=list[index];
							console.log(item)
							var key="key_"+item.jobId;
							if(that.jobIdList.indexOf(key)>0){
								continue
							}
							that.jobIdList.push(key)
							tempList.push(item);
							
						}
						that.list=that.list.concat(tempList)
					}, function(err) {
						console.log('返回错误回调', err)
						that.loading = false;
					})

			},
		}
	}
</script>

<style>
	@import url("../../common/uni.css");
</style>